package com.soft.webharvest.util;

import java.util.HashMap;
import java.util.Properties;

import com.soft.webharvest.util.ConfigFactory.Config;

public class ConfigFactory
{
	private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Config.class);
	private static java.util.Properties paraProps = new Properties();
	private static java.util.Map configs = java.util.Collections.synchronizedMap(new HashMap());

	private ConfigFactory()
	{
	}

	public static Config getConfig(java.lang.String path)
	{
		Config config = (Config)configs.get(path);
		if (config == null)
			config = new Config(path);
		return config;
	}
	
	/* member class not found */
	public static class Config
	{

		private java.lang.String path;

		public java.lang.String getProperty(java.lang.String paraName)
		{
			return ConfigFactory.paraProps.getProperty(paraName);
		}

		public java.lang.String toString()
		{
			return (new StringBuilder()).append("Config<").append(path).append(">").toString();
		}

		private Config(java.lang.String path)
		{
			this.path = path;
			try
			{
				java.io.InputStream is = getClass().getResourceAsStream((new StringBuilder()).append("/").append(path).toString());
				ConfigFactory.paraProps.load(is);
				is.close();
			}
			catch (java.lang.Exception e)
			{
				log.error("Can Not read the file. Please make sure file :[{}] exists under the Classpath!", path);
				throw new IllegalArgumentException(e);
			}

		}
	}


	
}